// add for MIDSPO-1345 "Time and Date Format" by ECARX:wenda.zhao start
#ifndef ECARX_VHAL_UNIT_UTILS_H
#define ECARX_VHAL_UNIT_UTILS_H

#include "PlatformProperty.h"

namespace ecarx::vhal::core::property::UnitUtil {
    
    // 获取包含所有单位的值的结构体 IndcnUnit，每次进行单位设定时都需要对其他相关单位进行设定！
    template <typename T>
    void getCurrentIndcnUnit(IndcnUnit& indcnUnit, T propertyObj){
        ALOGD("getCurrentIndcnUnit : start ");
        int32_t lTunit = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(VehicleProperty::HVAC_TEMPERATURE_DISPLAY_UNITS), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lTunit == toInt(VehicleUnit::CELSIUS)) {
            indcnUnit.indcnUnitTUnit = toInt(sdb::AmbTIndcdUnit::Celsius);
        } else {
            indcnUnit.indcnUnitTUnit = toInt(sdb::AmbTIndcdUnit::Fahrenheit);
        }
        
        int32_t lSpdunit = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(VehicleProperty::VEHICLE_SPEED_DISPLAY_UNITS), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lSpdunit == toInt(VehicleUnit::KILOMETERS_PER_HOUR)) {
            indcnUnit.indcnUnitSpdUnit = toInt(sdb::VehSpdIndcdUnit::Kmph);
        } else {
            indcnUnit.indcnUnitSpdUnit = toInt(sdb::VehSpdIndcdUnit::Mph);
        }

        int32_t lClkFmt = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(ECarXVehicleProperty::FUNC_UNIT_TIME_INDICATION), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lClkFmt == toInt(TimeFormat::TIME_12H)) {
            indcnUnit.indcnUnitClkFmt = toInt(sdb::TimeFormat::_12h);
        } else {
            indcnUnit.indcnUnitClkFmt = toInt(sdb::TimeFormat::_24h);
        }
        ALOGD("getCurrentIndcnUnit : lClkFmt=[%d]", lClkFmt);

        int32_t lDateFmt = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(ECarXVehicleProperty::SETTING_FUNC_UNIT_DATE_INDICATION), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lDateFmt == toInt(DateFormat::DATE_YMD)) {
            indcnUnit.indcnUnitDateFmt = toInt(sdb::DateFmt::DateFmt1);
        } else if (lDateFmt == toInt(DateFormat::DATE_MDY)) {
            indcnUnit.indcnUnitDateFmt = toInt(sdb::DateFmt::DateFmt2);
        } else {
            indcnUnit.indcnUnitDateFmt = toInt(sdb::DateFmt::DateFmt3);
        }
        ALOGD("getCurrentIndcnUnit : lDateFmt=[%d]", lDateFmt);

        int32_t lDstLong = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(VehicleProperty::DISTANCE_DISPLAY_UNITS), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lDstLong == toInt(VehicleUnit::KILOMETER)) {
            indcnUnit.indcnUnitDstLong = toInt(sdb::DstLong::Km);
        } else {
            indcnUnit.indcnUnitDstLong = toInt(sdb::DstLong::Miles);
        }

        int32_t lDstSho = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(ECarXVehicleProperty::FUNC_UNIT_SHORT_DISTANCE), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lDstSho == toInt(VehicleDstShoUnit::METER)) {
            indcnUnit.indcnUnitDstSho = toInt(sdb::DstSho::Mtr);
        } else {
            indcnUnit.indcnUnitDstSho = toInt(sdb::DstSho::Ft);
        }

        int32_t lFuCnsUnit = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(ECarXVehicleProperty::FUNC_UNIT_FUEL_CONSUMPTION), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lFuCnsUnit == toInt(FuelConsumptionUnit::L_100KM)) {
            indcnUnit.indcnUnitFuCnsUnit = toInt(sdb::FuCnsIndcdUnit::LperHectoKiloM);
        } else if (lFuCnsUnit == toInt(FuelConsumptionUnit::L_KM)) {
            indcnUnit.indcnUnitFuCnsUnit = toInt(sdb::FuCnsIndcdUnit::KiloMPerL);
        } else if (lFuCnsUnit == toInt(FuelConsumptionUnit::MSG_US)) {
            indcnUnit.indcnUnitFuCnsUnit = toInt(sdb::FuCnsIndcdUnit::MilePerGallonUsa);
        } else {
            indcnUnit.indcnUnitFuCnsUnit = toInt(sdb::FuCnsIndcdUnit::MilePerGallonEngland);
        }

        int32_t lVolUnit = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(ECarXVehicleProperty::FUEL_VOLUME_DISPLAY_UNITS), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lVolUnit == toInt(VehicleUnit::LITER)) {
            indcnUnit.indcnUnitVolUnit = toInt(sdb::VolUnit::Litre);
        } else if (lVolUnit == toInt(VehicleUnit::US_GALLON)) {
            indcnUnit.indcnUnitVolUnit = toInt(sdb::VolUnit::Gallon1);
        } else {
            indcnUnit.indcnUnitVolUnit = toInt(sdb::VolUnit::Gallon2);
        }
        
        int32_t lPunit = propertyObj -> template getPropertyValue<int32_t>(static_cast<int32_t>(VehicleProperty::TIRE_PRESSURE_DISPLAY_UNITS), static_cast<int32_t>(VehicleArea::GLOBAL));
        if (lPunit == toInt(VehicleUnit::KILOPASCAL)) {
            indcnUnit.indcnUnitPUnit = toInt(sdb::PUnit::Pa);
        } else if (lPunit == toInt(VehicleUnit::BAR)) {
            indcnUnit.indcnUnitPUnit = toInt(sdb::PUnit::Bar);
        }  else {
            indcnUnit.indcnUnitPUnit = toInt(sdb::PUnit::Psi);
        }

        VHALOG.d("UnitUtil.getCurrentIndcnUnit: Tunit[%d],Spdunit[%d],ClkFmt[%d],DateFmt[%d],DstLong[%d],DstSho[%d],FuCnsUnit[%d],VolUnit[%d],Punit[%d]", lTunit,lSpdunit,lClkFmt,lDateFmt,lDstLong,lDstSho,lFuCnsUnit,lVolUnit,lPunit);

        indcnUnit.indcnUnitIdPenForUnit = propertyObj -> getCurrentProfileID();
    }
}



#endif

// add for MIDSPO-1345 "Time and Date Format" by ECARX:wenda.zhao end